define([
  'jquery',
  'jquery-ui',
    'underscore',
	'backbone',
  './programsModel',
  './programsView',
  './pubsub'
], function( $, _ui, _, Backbone, ProgramsModel, ProgramsView, pubsub ) {
  "use strict";

  // set Backbone's internal jQuery reference to our jQuery ref.
  Backbone.$ = $;

  var 
    exports = {},
    _programsView;

  exports.init = function(){
    _programsView = new ProgramsView({ model : ProgramsModel });
    _programsView.render();

  } ;


  //pubsub event handler
  pubsub.on( 'nextStep', function( message ) {
    var from = message.from,
        index = message.index;
    _programsView.model.at( index ).set( { 'currentIndex' : 1});
    //Todo: send ajax call
    if( from === 'intro' ){
      _programsView._reload( index );

    }



//    console.dir(_programsView.model);


  });

  return exports;

});